package com.ftg.learn.controller;

import com.ftg.learn.service.AiService;
import com.ftg.learn.service.ChatHistoryService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 2234
 */
@RestController
public class AiDemoController {
    @Resource
    private AiService aiService;
    @Resource
    private ChatHistoryService chatHistoryService;

    @GetMapping("/say")
    public String say(@RequestParam(value = "sessionId", required = false, defaultValue = "default") String sessionId,
                      @RequestParam("message") String message) {
        // 使用带会话ID的方法来保持对话历史
        return aiService.chat(sessionId, message);
    }
    @GetMapping("/history")
    public List<String> getHistory(@RequestParam(value = "sessionId", required = false, defaultValue = "default") String sessionId) {
        List<String> history = chatHistoryService.getReadableChatHistory(sessionId);
        // 添加调试信息
        List<String> debugHistory = new ArrayList<>(history);
        debugHistory.add(0, "请求的sessionId: " + sessionId);
        return debugHistory;
    }

}
